package neptune.manager.builder;

import java.util.Random;

import neptune.manager.utils.IllegalValueException;

public class MACBuilderTEST {
	private static String[] hexCyphers = new String[] { "0", "1", "2", "3",
			"4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
	private static String[] hexSecondByteAllowedCyphers = new String[] { "2",
			"6", "A", "E" };

	/**
	 * @param args
	 * @throws IllegalValueException
	 */
	public static void main(String[] args) {
		for (int i = 0; i < 15; i++) {
			System.out.println(generateRandomMAC());
			System.out.println(generateRandomMAC2());
		}

	}

	private static String generateRandomMAC() {

		String[] address = new String[12];
		Random rand = new Random();
		for (int i = 0; i < address.length; i++) {
			int index = rand.nextInt(hexCyphers.length);

			address[i] = hexCyphers[index];
		}

		int index = rand.nextInt(hexSecondByteAllowedCyphers.length);
		address[1] = hexSecondByteAllowedCyphers[index];

		String composedAddress = "";
		for (int i = 0; i < address.length; i++) {
			composedAddress += address[i];
			if (i % 2 != 0 && i != address.length - 1)
				composedAddress += ":";
		}
		return composedAddress;
	}

	public static String generateRandomMAC2() {

		String[] address = new String[12];
		double[] indexes = new double[hexCyphers.length];
		for (int j = 0; j < indexes.length; j++)
			indexes[j] = (double) j / indexes.length;

		for (int i = 0; i < address.length; i++) {
			double rand = Math.random();

			int index = 0;
			while (index < hexCyphers.length-1 && rand > indexes[index])
				index++;

			address[i] = hexCyphers[index];
		}

		double rand = Math.random();
		indexes = new double[hexSecondByteAllowedCyphers.length];
		for (int j = 0; j < indexes.length; j++)
			indexes[j] = j / indexes.length;

		int index = 0;
		while (index < hexSecondByteAllowedCyphers.length-1 && rand > indexes[index])
			index++;
		address[1] = hexSecondByteAllowedCyphers[index];

		String composedAddress = "";
		for (int i = 0; i < address.length; i++) {
			composedAddress += address[i];
			if (i % 2 != 0 && i != address.length - 1)
				composedAddress += ":";
		}
		return composedAddress;
	}
}
